/*********************************************************************
	filename:	DaterMessageQueue.cpp
	created:	11/5/2012
	author:		4Ys
	
	purpose:	Implements message queue class.
*********************************************************************/
#include "DaterMessageQueue.h"

namespace Dater
{
	//----------------------------------------------------------------------------//
	template<> RecvMessageQueue* Singleton<RecvMessageQueue>::ms_Singleton = 0;

	//----------------------------------------------------------------------------//
	template<> SendMessageQueue* Singleton<SendMessageQueue>::ms_Singleton = 0;

	//----------------------------------------------------------------------------//
	MessageQueue::MessageQueue()
	{
		_locked = false;
	}

	//----------------------------------------------------------------------------//
	void MessageQueue::push(std::string message)
	{
		_messageQueue.push(message);
	}

	//----------------------------------------------------------------------------//
	std::string MessageQueue::front()
	{
		return _messageQueue.front();
	}

	//----------------------------------------------------------------------------//
	void MessageQueue::pop()
	{
		_messageQueue.pop();
	}

	//----------------------------------------------------------------------------//
	bool MessageQueue::isLocked()
	{
		return _locked;
	}

	//----------------------------------------------------------------------------//
	void MessageQueue::lock()
	{
		if(!_locked)
			_locked = true;
	}

	//----------------------------------------------------------------------------//
	void MessageQueue::unLock()
	{
		if(_locked)
			_locked = false;
	}

	//----------------------------------------------------------------------------//
	unsigned int MessageQueue::size()
	{
		return _messageQueue.size();
	}

	//----------------------------------------------------------------------------//
	void MessageQueue::pushMessageToBuffer(std::string message)
	{
		_messageBuffer.push(message);
	}

	//----------------------------------------------------------------------------//
	void MessageQueue::pushBufferToQueue()
	{
		while(_messageBuffer.size() != 0)
		{
			_messageQueue.push(_messageBuffer.front());
			_messageBuffer.pop();
		}
	}

	//----------------------------------------------------------------------------//
}